package com.wangyb.wework.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.wangyb.wework.bo.WwGroupchatMemberQueryBo;
import com.wangyb.wework.bo.WwGroupchatQueryBo;
import com.wangyb.wework.service.contact.IWwGroupchatMemberService;
import com.wangyb.wework.service.contact.IWwGroupchatService;
import com.wangyb.wework.vo.WwGroupchatMemberVo;
import com.wangyb.wework.vo.WwGroupchatVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 客户群列表Controller
 *
 * @Author: wangyb
 * @Date: 2021/7/8 10:58 上午
 */
@Api(value = "客户群列表控制器", tags = {"客户群列表管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wework/groupchat")
public class WwGroupchatController extends BaseController {
	@Autowired
	private IWwGroupchatService iWwGroupchatService;
	@Autowired
	private IWwGroupchatMemberService iWwGroupchatMemberService;
	/**
	 * 查询客户群列表列表
	 */
	@ApiOperation("查询客户群列表列表")
	@PreAuthorize("@ss.hasPermi('wework:groupchat:list')")
	@GetMapping("/list")
	public TableDataInfo<WwGroupchatVo> list(@Validated WwGroupchatQueryBo bo) {
		Long corpId = 1L;
		return iWwGroupchatService.index(corpId,bo);
	}
	/**
	 * 获取客户群成员详细信息
	 * wework/groupchat/listMember
	 */
	@ApiOperation("获取客户群成员详细信息")
	@PreAuthorize("@ss.hasPermi('wework:groupchat:member')")
	@GetMapping("/listMember/{id}")
	public TableDataInfo<WwGroupchatMemberVo> getInfo(@NotNull(message = "主键不能为空")
											 @PathVariable("id") Long id, @Validated WwGroupchatMemberQueryBo bo) {
		if (bo == null){
			bo = new WwGroupchatMemberQueryBo();
		}
		bo.setGroupchatId(id);
		return iWwGroupchatMemberService.queryPageList(bo);
	}
	@ApiOperation("同步所有客户群")
	@PreAuthorize("@ss.hasPermi('wework:groupchat:syncAll')")
	@PostMapping("/syncAll")
	public AjaxResult syncAllGroupchat(){
		Long corpId = 1L;
		iWwGroupchatService.syncGroupchat(corpId);
		return AjaxResult.success();
	}
	@ApiOperation("同步指定客户群")
	@PreAuthorize("@ss.hasPermi('wework:groupchat:sync')")
	@PostMapping("/sync/{wxChatId}")
	public AjaxResult syncGroupchat(@PathVariable("wxChatId") String wxChatId){
		Long corpId = 1L;
		iWwGroupchatService.syncGroupchat(corpId,wxChatId);
		return AjaxResult.success();
	}
}
